Module codecs :: Class Codec
[show private | hide private]
[frames | no frames]

Class Codec

Known Subclasses:
Codec, StreamReader, StreamWriter

Defines the interface for stateless encoders/decoders.

The .encode()/.decode() methods may use different error
handling schemes by providing the errors argument. These
string values are predefined:

 'strict' - raise a ValueError error (or a subclass)
 'ignore' - ignore the character and continue with the next
 'replace' - replace with a suitable replacement character;
            Python will use the official U+FFFD REPLACEMENT
            CHARACTER for the builtin Unicode codecs on
            decoding and '?' on encoding.
 'xmlcharrefreplace' - Replace with the appropriate XML
                       character reference (only for encoding).
 'backslashreplace'  - Replace with backslashed escape sequences
                       (only for encoding).

The set of allowed values can be extended via register_error.

Method Summary
  decode(self, input, errors)
Decodes the object input and returns a tuple (output object, length consumed).
  encode(self, input, errors)
Encodes the object input and returns a tuple (output object, length consumed).

Method Details

decode(self, input, errors='strict')

Decodes the object input and returns a tuple (output object, length consumed).

input must be an object which provides the bf_getreadbuf buffer slot. Python strings, buffer objects and memory mapped files are examples of objects providing this slot.

errors defines the error handling to apply. It defaults to 'strict' handling.

The method may not store state in the Codec instance. Use StreamCodec for codecs which have to keep state in order to make encoding/decoding efficient.

The decoder must be able to handle zero length input and return an empty object of the output object type in this situation.

encode(self, input, errors='strict')

Encodes the object input and returns a tuple (output object, length consumed).

errors defines the error handling to apply. It defaults to 'strict' handling.

The method may not store state in the Codec instance. Use StreamCodec for codecs which have to keep state in order to make encoding/decoding efficient.

The encoder must be able to handle zero length input and return an empty object of the output object type in this situation.

Generated by Epydoc 2.1 on Fri Aug 15 18:58:27 2008 http://epydoc.sf.net